<template>
  <div class="app">
    <el-header class="topbar">
      <div class="header-content">
        <router-link to="/" class="logo">🎬 KK电影网</router-link>
        <el-menu
          :default-active="$route.path"
          mode="horizontal"
          class="nav-menu"
          background-color="transparent"
          text-color="#cfe1ff"
          active-text-color="#4f8cff"
          router
        >
          <el-menu-item index="/">首页</el-menu-item>
          <el-menu-item index="/news">资讯</el-menu-item>
          <el-menu-item v-if="userStore.isLoggedIn" index="/favorites">收藏</el-menu-item>
          <el-menu-item v-if="userStore.isLoggedIn" index="/history">历史</el-menu-item>
        </el-menu>
        <div class="user-menu">
          <UserMenu />
        </div>
      </div>
    </el-header>
    <el-main class="main-content">
      <router-view />
    </el-main>
    <el-footer class="footer">© 2025 Vue 电影网站演示</el-footer>
  </div>
</template>

<script setup>
import { onMounted } from 'vue';
import { useUserStore } from './store/user';
import UserMenu from './components/UserMenu.vue';

const userStore = useUserStore();

onMounted(async () => {
  // 初始化用户数据和偏好设置
  if (userStore.isLoggedIn) {
    userStore.initPreferences();
    await userStore.initUserData();
  }
});
</script>

<style>
:root { --bg:#0f1217; --card:#181c24; --text:#e9eef9; --muted:#9aa6b2; --primary:#4f8cff; }
* {
  box-sizing: border-box;
}
html, body, #app { 
  height: 100%; 
  margin: 0; 
  padding: 0; 
  background: var(--bg); 
  color: var(--text); 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  width: 100%;
}
.app { 
  min-height: 100vh; 
  display: flex; 
  flex-direction: column; 
  width: 100%;
}
.topbar { 
  position: sticky; 
  top:0; 
  z-index:10; 
  background: rgba(15,18,23,.95); 
  border-bottom: 1px solid #222631; 
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  padding: 0;
  height: auto;
}
.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 20px;
  max-width: 1200px;
  margin: 0 auto;
  height: 64px;
}
.logo { 
  font-weight: 700; 
  letter-spacing: .5px; 
  color: var(--text); 
  text-decoration: none; 
  font-size: 1.25rem;
  margin-right: 20px;
}
.nav-menu {
  flex: 1;
  border-bottom: none !important;
}
.nav-menu .el-menu-item {
  height: 64px;
  line-height: 64px;
  border-bottom: 2px solid transparent;
  transition: all 0.3s ease;
}
.nav-menu .el-menu-item:hover {
  background: rgba(79, 140, 255, 0.1) !important;
  color: var(--primary) !important;
}
.nav-menu .el-menu-item.is-active {
  background: rgba(79, 140, 255, 0.15) !important;
  border-bottom-color: var(--primary) !important;
}
.user-menu { 
  display: flex; 
  align-items: center; 
  gap: 12px; 
}
.user-info { 
  display: flex; 
  align-items: center; 
  gap: 8px; 
  text-decoration: none; 
  color: var(--text); 
}
.username { 
  font-weight: 500; 
}
.logout-btn, .login-btn { 
  padding: 8px 16px; 
  border: 1px solid var(--primary); 
  border-radius: 6px; 
  background: transparent; 
  color: var(--primary); 
  cursor: pointer; 
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
}
.logout-btn:hover, .login-btn:hover { 
  background: var(--primary); 
  color: white; 
}
.main-content {
  flex: 1;
  padding: 0;
  background: var(--bg);
}
.footer { 
  border-top: 1px solid #222631; 
  color: var(--muted); 
  padding: 20px; 
  text-align: center; 
  font-size: 0.875rem;
  background: var(--bg);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-content {
    padding: 0 12px;
    gap: 12px;
    flex-wrap: wrap;
    height: auto;
    min-height: 64px;
  }
  .logo {
    margin-right: 0;
    font-size: 1.1rem;
  }
  .nav-menu {
    order: 3;
    width: 100%;
    margin-top: 8px;
  }
  .nav-menu .el-menu-item {
    height: 48px;
    line-height: 48px;
    font-size: 0.875rem;
  }
  .user-menu {
    margin-left: auto;
  }
}
</style>